package com.xxrl.shop.repository;

import com.xxrl.shop.domain.Address;
import com.xxrl.shop.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author mis
 */
public interface AddressRepository extends JpaRepository<Address,Long> {

    /**
     * 根据用户查询
     * @param user 用户
     * @return 地址列表
     */
    List<Address> findAllByUser(User user);

    /**
     * 查询用户的默认地址
     * @param user 用户
     * @return 地址
     */
    @Query("select a from Address a where a.user = :user and a.isDefault = true")
    Address findTopByUserAndIsDefault(User user);
}
